package com.itboye.lottery.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.bylibrary.util.TimeUtils;
import com.itboye.bylibrary.widget.glide.GlideUtil;
import com.itboye.lottery.R;
import com.itboye.lottery.alert.ByAlert;
import com.itboye.lottery.base.BaseActivity;
import com.itboye.lottery.bean.FindBean;
import com.itboye.lottery.presenter.UserPresenter;
import com.itboye.lottery.retrofit.ResponseCallback;
import com.itboye.lottery.widget.medium_textview.MediumTextView;

import org.jetbrains.annotations.NotNull;


public class FindDetailActivity extends BaseActivity implements ResponseCallback {

    TextView tv_find_detail_title, tv_find_detail_time, tv_find_detail_read_num;
    MediumTextView tv_find_detail_content;
    ImageView iv_find_detail_img;
    UserPresenter userPresenter = new UserPresenter(this);
    private int position;
    private String articalId;
    private FindBean findBean;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_find_detail;
    }

    @Override
    protected void initData() {
        position = getIntent().getIntExtra("position", 0);
        articalId = getIntent().getStringExtra("article_id");
        setTitle(getIntent().getStringExtra("title"));
        switch (position) {
            case 0:
//                userPresenter.wanFaDetail();
                break;
            case 1:
                userPresenter.newsDetail(articalId);
                break;
            case 2:
                iv_find_detail_img.setVisibility(View.VISIBLE);
                userPresenter.huoDongDetail(articalId);
                break;
            case 3:
                userPresenter.gongGaoDetail(articalId);
                iv_find_detail_img.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    public void onClick(View view) {
    }

    @Override
    public void success(@NotNull Object o, @NotNull String requestSuccessType) {
        //https://github.com/angebagui/medium-textview
        //https://github.com/PrivacyApps/html-textview 加載含有网页图片的字符串
        findBean = (FindBean) o;
        switch (position) {
            case 0:
                //http://t2.hddhhn.com/uploads/tu/201707/200/3.jpg
                GlideUtil.displayRatio(this, findBean.getImg(), iv_find_detail_img);
//                GlideUtil.displayRatio(this, "http://t2.hddhhn.com/uploads/tu/201707/200/3.jpg", iv_find_detail_img);
                tv_find_detail_content.setText((findBean.getContent()));
                break;
            case 1:
                tv_find_detail_title.setText(findBean.getTitle());
                tv_find_detail_time.setText(TimeUtils.getFormatTime(findBean.getAdd_time() * 1000, "yyyy-MM-dd   HH:mm"));
                tv_find_detail_read_num.setText("阅读" + findBean.getClick());
                String content = findBean.getContent();
//                        "<p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">根据《马卡报》的消息，今夏与阿森纳合同到期的卡索拉将会参加比利亚雷亚尔的季前训练。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px; text-align: center;\\\"><img src=\"http://t1.27270.com/uploads/tu/201809/242/5873409e41.jpg\" alt=\\\"\\\" style=\\\"border: 0px; max-width: 650px;\\\"/></p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　卡索拉过去2年饱受伤病的困扰，他的状态因此大受影响，而西班牙人与阿森纳的合同将于今年夏天到期。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　卡索拉今夏会成为一名自由球员，西班牙媒体Movistar+周末确认，卡索拉会在今夏参与到比利亚雷亚尔的季前训练。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　在黄潜西甲末轮2-2战平皇马的赛后，这则消息得到了黄潜大使塞纳的确认。卡索拉2003年加盟比利亚雷亚尔，在2006-07赛季被租借出去后，卡索拉2007年回归黄潜，2011年他加盟马拉加，并于2012年转会阿森纳。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">（转自：进球体育）</p><p><br/></p>";
//                content="<p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">根据《马卡报》的消息，今夏与阿森纳合同到期的卡索拉将会参加比利亚雷亚尔的季前训练。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px; text-align: center;\\\"><img src=\\\"/Uploads/ueditor/20180521/1526888110791816.jpg\\\" alt=\\\"\\\" style=\\\"border: 0px; max-width: 650px;\\\"/></p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　卡索拉过去2年饱受伤病的困扰，他的状态因此大受影响，而西班牙人与阿森纳的合同将于今年夏天到期。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　卡索拉今夏会成为一名自由球员，西班牙媒体Movistar+周末确认，卡索拉会在今夏参与到比利亚雷亚尔的季前训练。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">　　在黄潜西甲末轮2-2战平皇马的赛后，这则消息得到了黄潜大使塞纳的确认。卡索拉2003年加盟比利亚雷亚尔，在2006-07赛季被租借出去后，卡索拉2007年回归黄潜，2011年他加盟马拉加，并于2012年转会阿森纳。</p><p style=\\\"white-space: normal; margin: 0px auto 20px; padding: 0px; line-height: 25px; font-family: 宋体, arial, sans-serif; font-size: 14px;\\\">（转自：进球体育）</p><p><br/></p>";
//                tv_find_detail_content.setText((findBean.getContent()));
                tv_find_detail_content.setText(content);
                GlideUtil.displayRatio(this, findBean.getImg(), iv_find_detail_img);
//                GlideUtil.displayRatio(this, "http://t2.hddhhn.com/uploads/tu/201707/200/3.jpg", iv_find_detail_img);
                break;
            case 2:
                break;
            case 3:
                tv_find_detail_title.setText(findBean.getTitle());
                tv_find_detail_time.setText(TimeUtils.getFormatTime(findBean.getAdd_time() * 1000, "yyyy-MM-dd   HH:mm"));
                tv_find_detail_content.setText((findBean.getContent()));
                break;
        }

    }

    @Override
    public void fail(int code, @NotNull Object msg, @NotNull String requestErrorType) {
        ByAlert.alert(msg);
    }


}
